#include "loadingWnd_t.h"
#include "uiMutex_t.h"
#include "Tools.h"


gcn::Gui* loadingWnd_t::gui = NULL; 
gcn::Label* loadingWnd_t::lblLoading = NULL;
gcn::Icon* loadingWnd_t::backIcon = NULL;
gcn::Image* loadingWnd_t::backImage = NULL;
gcn::cartoonPic* loadingWnd_t::picLoading = NULL;

void loadingWnd_t::init(gcn::Gui* gui)
{
	UI_MUTEX

	if (lblLoading!=NULL) 
		release();

	loadingWnd_t::gui = gui;
	gcn::Container * cont = (gcn::Container *)gui->getTop();

 	backImage = gcn::Image::load("newpmClientRes//UI//loadingBack.png");
 	backIcon  = new gcn::Icon(backImage);
 	backIcon->setPosition(0,0);
 	cont->add(backIcon);

	lblLoading = new gcn::Label("loading...");
	lblLoading->setPosition((cont->getWidth()-lblLoading->getWidth())/2-50,(cont->getHeight()-lblLoading->getHeight())/2-70);
	cont->add(lblLoading);
	lblLoading->setForegroundColor(gcn::Color(0,0,0,230));

	picLoading = new gcn::cartoonPic();
	cont->add(picLoading);

	gcn::Image* image = gcn::Image::load("newpmClientRes//UI//loadRun_01.png");
	picLoading->addImage(image);
	image = gcn::Image::load("newpmClientRes//UI//loadRun_02.png");
	picLoading->addImage(image);
	image = gcn::Image::load("newpmClientRes//UI//loadRun_03.png");
	picLoading->addImage(image);
	image = gcn::Image::load("newpmClientRes//UI//loadRun_04.png");
	picLoading->addImage(image);
	image = gcn::Image::load("newpmClientRes//UI//loadRun_05.png");
	picLoading->addImage(image);
	image = gcn::Image::load("newpmClientRes//UI//loadRun_06.png");
	picLoading->addImage(image);

	picLoading->setTrans(80);
	picLoading->setVisible(true);
	picLoading->setDelayTime(100);
	picLoading->setPosition(lblLoading->getX()+lblLoading->getWidth()+15, lblLoading->getY()-picLoading->getHeight()/2);
}


void loadingWnd_t::release()
{
	UI_MUTEX
	safe_delete(lblLoading);
	safe_delete(backImage);
	safe_delete(backIcon);
	safe_delete(picLoading);
}